#include <cstring>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <queue>
#include <sstream>
#include <cstdlib>
#define MAX_N 600
using namespace std;
int n;

struct lnode
{
    char val;
    int tx,ty,sz;
    int lt,rt,lb,rb,fa;
    bool is_end;
    bool visited;

    char *toString()
    {
        char * buff = (char *)malloc(1000 * sizeof(char));
        sprintf(buff,"val=%c, lt=%d, rt=%d, lb=%d, rb=%d, visited=%s, is_end=%s",
                val==0?'Q':val,lt,rt,lb,rb,visited?"TRUE":"FALSE",is_end?"TRUE":"FALSE");
        return  buff;
    }
} tree[MAX_N*MAX_N];
int tree_cnt = 0;

int pos[MAX_N][MAX_N];


int mktree(int x,int y ,int sz)
{
    if(sz==0) return -1;
    sz >>= 1;
    int lt = mktree(x,y,sz);
    int rt = mktree(x,y+sz,sz);
    int lb = mktree(x+sz,y,sz);
    int rb = mktree(x+sz,y+sz,sz);
    tree_cnt++;
    tree[tree_cnt].lt = lt;
    tree[tree_cnt].rt = rt;
    tree[tree_cnt].lb = lb;
    tree[tree_cnt].rb = rb;
    tree[lt].fa = tree_cnt;
    tree[rt].fa = tree_cnt;
    tree[lb].fa = tree_cnt;
    tree[rb].fa = tree_cnt;
    if (sz==0) pos[x][y] = tree_cnt;

    return tree_cnt;
}

char buff[10000];

int get_num(string s)
{
    stringstream ss;
    ss.flags(ios::hex);
    ss<<s;
    int x;
    ss >> x;
    return x;
}

void init(int line, char *buff)
{
    int len = strlen(buff);
    int p = 0,sum = 0;
    string st = "  ";
    for (int i = 0 ; i< len ; i++)
    {
        if (buff[i]=='x')
        {
            st[0] = buff[i+1];
            st[1] = buff[i+2];
            sum = get_num(st);
        }
        if (buff[i]==',')
            for (int j = 0 ; j < 8 ; j++,p++)
            {
                tree[pos[line][p]].val = (sum&(1<<j))?'B':'W';
                //cout << line << " "<<p<< " "<<pos[line][p]<<endl;
                tree[pos[line][p]].is_end = true;
            }
    }

}

void del_tree()
{
    queue<int> que;
    for (int i = 0 ; i < n; i++)
    {
        for (int j = 0 ; j < n; j++)
        {

            que.push(pos[i][j]);
        }
    }

    for (; !que.empty(); que.pop())
    {
        int fa = tree[que.front()].fa;
        if (tree[fa].visited) continue;
        tree[fa].visited = true;
        int lt = tree[fa].lt;
        int rt = tree[fa].rt;
        int lb = tree[fa].lb;
        int rb = tree[fa].rb;
        if (tree[lt].is_end && tree[rt].is_end && tree[lb].is_end && tree[rb].is_end)
        {
            char color = tree[lt].val;
            if (tree[lt].val == color && tree[rt].val == color && tree[lb].val == color && tree[rb].val == color)
            {

                tree[fa].is_end = true;
                tree[fa].val = color;
            }
        }

        que.push(fa);
    }
}

void dfs(int root)
{
    if (tree[root].is_end) printf("%c",tree[root].val);
    else
    {
        printf("Q");
        dfs(tree[root].lt);
        dfs(tree[root].rt);
        dfs(tree[root].lb);
        dfs(tree[root].rb);
    }
}

void print_tree(){
    for(int i = 1 ; i <= tree_cnt ; i++)
    {
        cout <<"#" << i <<" : " << tree[i].toString()<<endl;
    }
}

int main()
{

   // freopen("2270.txt","r",stdin);
   // freopen("2270.out","w",stdout);
    scanf("%*s%*s%d",&n);
    scanf("%*s%*s%d",&n);
    int x;
    tree_cnt = 0;
    memset(tree,0,sizeof(tree));
    scanf("%*s%*s%*s%*s%*s");
    int root  = mktree(0,0,n);



    for (int i = 0 ; i < n ; i++)
    {
        scanf("%s",buff);
        init(i,buff);
    }

    del_tree();
    cout << n <<endl;
    dfs(root);

    return 0;
}
